<?php
/**
 * @package     Joomla.Administrator
 * @subpackage  com_users
 *
 * @copyright   Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

// Include the component HTML helpers.
JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');

JHtml::_('behavior.formvalidation');
JHtml::_('formbehavior.chosen', 'select');

// Get the form fieldsets.
$fieldsets = $this->form->getFieldsets();
?>
<script type="text/javascript">
	Joomla.submitbutton = function(task)
	{
		if (task == 'user.cancel' || document.formvalidator.isValid(document.id('user-form')))
		{
			Joomla.submitform(task, document.getElementById('user-form'));
		}
	}

	Joomla.twoFactorMethodChange = function(e)
	{
		var selectedPane = 'com_users_twofactor_' + jQuery('#jform_twofactor_method').val();

		jQuery.each(jQuery('#com_users_twofactor_forms_container>div'), function(i, el) {
			if (el.id != selectedPane)
			{
				jQuery('#' + el.id).hide(0);
			}
			else
			{
				jQuery('#' + el.id).show(0);
			}
		});
	}
</script>

<form action="<?php echo JRoute::_('index.php?option=com_users&layout=edit&id='.(int) $this->item->id); ?>" method="post" name="adminForm" id="user-form" class="form-validate form-horizontal" enctype="multipart/form-data">
	<?php echo JLayoutHelper::render('joomla.edit.item_title', $this); ?>
	<fieldset>
		<?php echo JHtml::_('bootstrap.startTabSet', 'myTab', array('active' => 'details')); ?> <?php echo JHtml::_('bootstrap.addTab', 'myTab', 'details', JText::_('COM_USERS_USER_ACCOUNT_DETAILS', true)); ?> 
		<div class="tab-pane active" id="details"> 
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_username" id="jform_username-lbl" data-original-title="&lt;strong&gt;Login Name&lt;/strong&gt;&lt;br /&gt;Enter the login name (Username) for the user."> Tên đăng nhập<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<input type="text" aria-required="true" required size="30" class="required" value="<?php echo $this->item->username;?>" id="jform_username" name="jform[username]">
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip" for="jform_password" id="jform_password-lbl" data-original-title="&lt;strong&gt;Password&lt;/strong&gt;&lt;br /&gt;Enter the password for the user"> Mật khẩu</label>
				</div>
				<div class="controls">
					<input type="password" maxlength="99" size="30" class="validate-password" autocomplete="off" value="" id="jform_password" name="jform[password]">
				</div>
			</div>
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip" for="jform_password2" id="jform_password2-lbl" data-original-title="&lt;strong&gt;Confirm Password&lt;/strong&gt;&lt;br /&gt;Confirm the user's password"> Lặp lại mật khẩu</label>
				</div>
				<div class="controls">
					<input type="password" maxlength="99" size="30" class="validate-password" autocomplete="off" value="" id="jform_password2" name="jform[password2]">
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_name" id="jform_name-lbl" data-original-title="&lt;strong&gt;Name&lt;/strong&gt;&lt;br /&gt;Enter the name of the user"> Họ tên<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<input type="text" aria-required="true" required size="30" class="required" value="<?php echo $this->item->name;?>" id="jform_name" name="jform[name]">
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_email" id="jform_email-lbl" data-original-title="&lt;strong&gt;Email&lt;/strong&gt;&lt;br /&gt;Enter an email for the user"> Email<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<input type="email" aria-required="true" required size="30" value="<?php echo $this->item->email;?>" id="jform_email" class="validate-email required" name="jform[email]">
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_gender" id="jform_gender-lbl" data-original-title=""> Giới tính<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<input type="radio" aria-required="true" value="1" class="required" name="jform[gender]" style="margin-top:0px;" <?php echo $this->item->gender==1?"checked":"";?>> Nam
					<input type="radio" aria-required="true" value="2" class="required" name="jform[gender]" style="margin-top:0px;" <?php echo $this->item->gender==2?"checked":"";?>> Nữ
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_birthday" id="jform_birthday-lbl"> Ngày sinh<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<select name="jform[day]" style="width:70px;">
						<?php for($i=1; $i<=31; $i++){?>
						<option value="<?php echo $i;?>" <?php if($this->item->day == $i) echo "selected";?>><?php echo $i;?></option>
						<?php }?>
					</select>
					<select name="jform[month]" style="width:70px;">
						<?php for($i=1; $i<=12; $i++){?>
						<option value="<?php echo $i;?>" <?php if($this->item->month == $i) echo "selected";?>><?php echo $i;?></option>
						<?php }?>
					</select>
					<select name="jform[year]" style="width:70px;">
						<?php for($i=1900; $i<2015; $i++){?>
						<option value="<?php echo $i;?>" <?php if($this->item->year == $i) echo "selected";?>><?php echo $i;?></option>
						<?php }?>
					</select>
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_address" id="jform_address-lbl" data-original-title=""> Địa chỉ<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<input type="text" aria-required="true" size="30" value="<?php echo $this->item->address;?>" id="jform_address" name="jform[address]">
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_phone" id="jform_phone-lbl" data-original-title=""> Điện thoại<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<input type="text" aria-required="true" size="30" value="<?php echo $this->item->phone;?>" id="jform_phone" name="jform[phone]">
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_work_time" id="jform_work_time-lbl" data-original-title=""> Thời gian công tác<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<?php $editor = JFactory::getEditor();
					echo $editor->display("jform[work_time]", $this->item->work_time, "400", "100", "150", "20", 1, null, null, null, array('mode' => 'advanced'));
					?>
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_position" id="jform_position-lbl" data-original-title=""> Vị trí ứng tuyển<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<input type="text" aria-required="true" size="30" value="<?php echo $this->item->position;?>" id="jform_position" name="jform[position]">
				</div>
			</div>
			
			<div class="control-group">
				<div class="control-label">
					<label title="" class="hasTooltip required" for="jform_quiz" id="jform_quiz-lbl" data-original-title=""> Bài trắc nghiệm<span class="star">&nbsp;*</span></label>
				</div>
				<div class="controls">
					<select name="jform[quiz]" style="width:250px;" class="required">
						<option value="0">Chọn một bài trắc nghiệm</option>
						<option value="1" <?php if($this->item->quiz == 1) echo "selected";?>>Đánh giá bản thân với công việc</option>
						<option value="2" <?php if($this->item->quiz == 2) echo "selected";?>>Đánh giá bản thân</option>
						<option value="3" <?php if($this->item->quiz == 3) echo "selected";?>>Đánh giá sự tự tin</option>
						<option value="4" <?php if($this->item->quiz == 4) echo "selected";?>>Mối quan hệ bản thân với người khác</option>
					</select>
				</div>
			</div>
			<input type="hidden" name="jform[sendEmail]" value="1" />
			<input type="hidden" name="jform[id]" value="<?php echo $this->item->id?$this->item->id:"0"?>" />
		</div>
		<?php /*foreach ($this->form->getFieldset('user_details') as $field) : ?>
		<div class="control-group">
			<div class="control-label"> <?php echo $field->label; ?> </div>
			<div class="controls"> <?php echo $field->input; ?> </div>
		</div>
		<?php endforeach; */?>
		<?php echo JHtml::_('bootstrap.endTab'); ?>
		<?php if ($this->grouplist) : ?>
		<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'groups', JText::_('COM_USERS_ASSIGNED_GROUPS', true)); ?> <?php echo $this->loadTemplate('groups'); ?> <?php echo JHtml::_('bootstrap.endTab'); ?>
		<?php endif; ?>
		<?php
			foreach ($fieldsets as $fieldset) :
				if ($fieldset->name == 'user_details') :
					continue;
				endif;
			?>
		<?php echo JHtml::_('bootstrap.addTab', 'myTab', $fieldset->name, JText::_($fieldset->label, true)); ?>
		<?php foreach ($this->form->getFieldset($fieldset->name) as $field) : ?>
		<?php if ($field->hidden) : ?>
		<div class="control-group">
			<div class="controls"> <?php echo $field->input; ?> </div>
		</div>
		<?php else: ?>
		<div class="control-group">
			<div class="control-label"> <?php echo $field->label; ?> </div>
			<div class="controls"> <?php echo $field->input; ?> </div>
		</div>
		<?php endif; ?>
		<?php endforeach; ?>
		<?php echo JHtml::_('bootstrap.endTab'); ?>
		<?php endforeach; ?>
		<?php if (!empty($this->tfaform) && $this->item->id): ?>
		<?php echo JHtml::_('bootstrap.addTab', 'myTab', 'twofactorauth', JText::_('COM_USERS_USER_TWO_FACTOR_AUTH', true)); ?>
		<div class="control-group">
			<div class="control-label">
				<label id="jform_twofactor_method-lbl" for="jform_twofactor_method" class="hasTooltip"
					   title="<strong><?php echo JText::_('COM_USERS_USER_FIELD_TWOFACTOR_LABEL') ?></strong><br/><?php echo JText::_('COM_USERS_USER_FIELD_TWOFACTOR_DESC') ?>"> <?php echo JText::_('COM_USERS_USER_FIELD_TWOFACTOR_LABEL'); ?> </label>
			</div>
			<div class="controls"> <?php echo JHtml::_('select.genericlist', Usershelper::getTwoFactorMethods(), 'jform[twofactor][method]', array('onchange' => 'Joomla.twoFactorMethodChange()'), 'value', 'text', $this->otpConfig->method, 'jform_twofactor_method', false) ?> </div>
		</div>
		<div id="com_users_twofactor_forms_container">
			<?php foreach($this->tfaform as $form): ?>
			<?php $style = $form['method'] == $this->otpConfig->method ? 'display: block' : 'display: none'; ?>
			<div id="com_users_twofactor_<?php echo $form['method'] ?>" style="<?php echo $style; ?>"> <?php echo $form['form'] ?> </div>
			<?php endforeach; ?>
		</div>
		<fieldset>
			<legend> <?php echo JText::_('COM_USERS_USER_OTEPS') ?> </legend>
			<div class="alert alert-info"> <?php echo JText::_('COM_USERS_USER_OTEPS_DESC') ?> </div>
			<?php if (empty($this->otpConfig->otep)): ?>
			<div class="alert alert-warning"> <?php echo JText::_('COM_USERS_USER_OTEPS_WAIT_DESC') ?> </div>
			<?php else: ?>
			<?php foreach ($this->otpConfig->otep as $otep): ?>
			<span class="span3"> <?php echo substr($otep, 0, 4) ?>-<?php echo substr($otep, 4, 4) ?>-<?php echo substr($otep, 8, 4) ?>-<?php echo substr($otep, 12, 4) ?> </span>
			<?php endforeach; ?>
			<div class="clearfix"></div>
			<?php endif; ?>
		</fieldset>
		<?php echo JHtml::_('bootstrap.endTab'); ?>
		<?php endif; ?>
		<?php echo JHtml::_('bootstrap.endTabSet'); ?>
	</fieldset>
	<input type="hidden" name="task" value="" />
	<?php echo JHtml::_('form.token'); ?>
</form>
